

var app = getApp();
Page({
  data: {
    shownew: false,
    successcollect: false,
    successshare: false,
    selectedCollect: '',
    carouselList: [],
    collectarr: [],
    modulearr: [],
    recommedarr: [],
    nowtypeid:null,
    showppppppp:true,
    backfrom:false
  },
  onLoad: function () { },
  onShow: function () {
    var vm = this;
    this.getCarousel();
    //拉取分类列表
    this.getTypeList();
    //拉取推荐文章
    this.getArticleList(this.data.nowtypeid)
  },
  ToCase: function (e) {
    this.setData({
      nowtypeid:e.currentTarget.dataset.a
    })
    if(e.currentTarget.dataset.a.length == 4){
      var vm = this;
      var userid = getApp().globalData.openid;
      if (userid) {
        var data = 
          {
            userid
          }
        wx.request({
          url: getApp().globalData.baseUrl + '/wago/safety/selectByType',
          method: 'post',
          data,
          header: {
            'Content-Type': 'application/x-www-form-urlencoded',
          },
          success: function (res) {
            vm.setData({
              Allrecommedarr: res.data.data,
              recommedarr:res.data.data.slice(0,10)
            })
            
          }
        })
      } else {
        wx.showToast({
          title: '请先登录',
          duration: 2000,
          icon: 'none'
        });
      }
    }else{
      this.getArticleList(e.currentTarget.dataset.a)
    }
    
  },
  //显示收藏
  showmodal: function (e) {
    this.clearCollect();
    //在data中保存当前的文章id
    this.setData({
      nowArticleid: e.currentTarget.dataset.articleid,
    });
    var vm = this;
    var oooid = getApp().globalData.openid;
    if (!oooid) {
      wx.showToast({
        title: '登录后才能使用该功能',
        duration: 2000,
        icon: 'none'
      });
    } else {
      wx.request({
        url: getApp().globalData.baseUrl + '/wago/wjj/selectByUserId',
        method: 'get',
        data: {
          userid: getApp().globalData.openid
        },
        success: function (res) {
          vm.setData({
            collectarr: res.data.data
          })
        }
      })
      this.setData({
        shownew: true
      })
    }
  },
  //关闭收藏
  onCloseNew: function () {
    this.setData({
      shownew: false
    })
    this.clearCollect();
  },
  //获取输入框的内容
  getInputContent:function(e){
    this.setData({
      searchInput:e.detail.value
    })
  },
  clrarInputpp:function(){
    this.setData({
      searchInput:''
    })
  },
  //确认收藏
  submitfile: function () {
    var vm = this;
    var wjjId = this.data.nowCollerctId;
    var userid = getApp().globalData.openid;
    var shoucangId = this.data.nowArticleid;
    var nowiiiii = this.data.nowCollerctIndex;
    if (nowiiiii == 999882) {
      wx.showToast({
        title: '请选择收藏夹',
        duration: 2000,
        icon: 'none'
      });
    } else {
      wx.request({
        url: getApp().globalData.baseUrl + '/wago/shoucang/add',
        method: 'put',
        data: {
          userid,
          shoucangId,
          wjjId
        },
        success: function (res) {
          vm.setData({
            shownew: false,
            successcollect: true,
            messagenow:res.data.message
          });
          vm.getArticleList(vm.data.nowtypeid)
          setTimeout(() => {
            vm.setData({
              successcollect: false
            });
          }, 1000);
          vm.clearCollect();
        }
      })
    }
  },
  //清除收藏夹信息
  clearCollect: function () {
    this.setData({
      nowArticleid: undefined,
      nowCollerctIndex: 999882,
      nowCollerctId: undefined
    });
  },
  //分享成功
  showsharemodal: function () {
    var vm = this;
    this.setData({
      successshare: true
    });
    setTimeout(() => {
      vm.setData({
        successshare: false
      });
    }, 1000);
  },
  //根据关键字模糊查询
  searchByKeyWord:function(){
    var vm = this
    var keyword = this.data.searchInput;
    var userid = getApp().globalData.openid;
    var data = {
      userid,
      string:this.data.searchInput
    }
    wx.request({
      url: getApp().globalData.baseUrl + '/wago/safety/selectByType',
      method: 'post',
      data,
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      success: function (res) {
        vm.setData({
          Allrecommedarr: res.data.data,
          recommedarr:res.data.data.slice(0,10)
        })
      }
    })

  },
  //拉取分类数据
  getTypeList: function () {
    var vm = this;
    wx.request({
      url: getApp().globalData.baseUrl + '/wago/type/select',
      method: 'post',
      data: {

      },
      success: function (res) {
        vm.setData({
          modulearr: res.data.data.list
        })

      }
    })
  },
  //根据分类拉取文章列表
  getArticleList: function (a) {
    var vm = this;
    var userid = getApp().globalData.openid;
    if (userid) {
      var typeid = a;
      var data = typeid ? {
        typeid,
        userid
      } :
        {
          userid
        }
      wx.request({
        url: getApp().globalData.baseUrl + '/wago/safety/selectByType',
        method: 'post',
        data,
        header: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
        success: function (res) {
          var nowssssss = vm.data.backfrom  ? res.data.data.length : 10
          vm.setData({
            Allrecommedarr: res.data.data,
            recommedarr:res.data.data.slice(0,nowssssss)
          })
          
        }
      })
    } else {
      var uuuuu = vm.data.nowtypeid ? {
        userid:'',
        typeid:vm.data.nowtypeid
      } : {
        userid:''
      }
      wx.request({
        url: getApp().globalData.baseUrl + '/wago/safety/selectByType',
        method: 'post',
        data:uuuuu,
        header: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
        success: function (res) {
          var nowssssss = vm.data.backfrom  ? res.data.data.length : 10
          vm.setData({
            Allrecommedarr: res.data.data,
            recommedarr:res.data.data.slice(0,nowssssss)
          })
          
        }
      })
    }
  },
  //查看文章详情
  toDetail: function (e) {
    var nowtypeid = this.data.nowtypeid
    //"&itemlist=" + JSON.stringify(this.data.Allrecommedarr)
    wx.navigateTo({
      url: "/pages/newInfo/newInfo?id=" + e.currentTarget.dataset.id + "&typeid="+nowtypeid
    })
  },
  onShareAppMessage: function () {
    let url = encodeURIComponent('/packageNews/pages/news_detail/news_detail?news_id=');
    return {
      title: "热点详情",
      path: `/pages/index/index`
    }

  },
  //获取轮播图
  getCarousel: function () {
    var vm = this;
    wx.request({
      url: getApp().globalData.baseUrl + '/wago/lunbotu/select',
      method: 'post',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      data: {
        cannel: 2
      },
      success: function (res) {
        vm.setData({
          carouselList: res.data.data
        })
      }
    })
  },
  //点击收藏文件夹的时候点击的那个高亮
  chooseCollect(e) {
    var id = e.currentTarget.dataset.idx;
    var index = e.currentTarget.dataset.index;
    this.setData({
      nowCollerctIndex: index,
      nowCollerctId: id
    })
  },
  //查看更多
  ShowmoreInfo:function(){
    var all = this.data.Allrecommedarr;
    var nowshow = all;
    this.setData({
      recommedarr:nowshow,
      showppppppp:false,
      backfrom:true
    })
  },
  add0: function (m) { return m < 10 ? '0' + m : m },



  format: function (shijianchuo) {
    //shijianchuo是整数，否则要parseInt转换
    var time = new Date(shijianchuo);
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    this.setData({
      createTT: y + '-' + this.add0(m) + '-' + this.add0(d)
    })


  },
  format22: function (shijianchuo) {
    //shijianchuo是整数，否则要parseInt转换
    var time = new Date(shijianchuo);
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return  y + '-' + this.add0(m) + '-' + this.add0(d)+ ' ' + this.add0(h)+ ':' + this.add0(mm)

  },
  getArticleInfo: function (a) {
    var userid = getApp().globalData.openid;
    var vm = this;
    wx.request({
      url: getApp().globalData.baseUrl + '/wago/safety/selectById',
      method: 'post',
      data: {
        id,
        userid
      },
      success: function (res) {
        vm.format(res.data.data.createTime)
        vm.setData({
          articleinfo: res.data.data,
          id: res.data.data.id,
          //nowshowcontent:'<p class="ql-align-justify"><span style="color: rgb(68, 68, 68);">家是我们心灵的港湾，家是我们在疲惫的时候可以随时休息的地方，累的时候我们都可以回到家里休息休息，再重新养活自己的精神，再重新找回自己的斗志。每套住房都承载了一个家的幸福，为此，无论是房屋买卖还是装修，都需要谨慎行事。</span></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><strong class="ql-size-large" style="color: rgb(68, 68, 68);"><em>贝壳平台 </em></strong><span style="color: rgb(68, 68, 68);">由链家网升级而来，是以技术驱动的品质居住服务平台，聚合和赋能全行业的优质服务者，打造开放的品质居住服务生态，致力于为两亿家庭提供包括二手房、新房、租赁和装修全方位居住服务。</span></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><span style="color: rgb(68, 68, 68);">在房屋买卖领域，贝壳凭借着 </span><strong class="ql-size-large" style="color: rgb(68, 68, 68);"><em>真信息、真价格、真体验、真服务 </em></strong><span style="color: rgb(68, 68, 68);">的经营理念，让买卖双方在交易过程中安心放心，因而也成为众多购房客户的优选平台。</span></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><span style="color: rgb(68, 68, 68);">然而贝壳将其值得信赖的优势继续延伸至装修领域，贝壳精工再起航，以品质施工为基点，对现有装修领域基础服务进行全面升级，助力装修行业成长。</span></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><strong class="ql-size-large" style="color: rgb(68, 68, 68);">德国万可电线连接器入选贝壳精工严选辅材产品</strong></p><p class="ql-align-justify"><strong class="ql-size-large" style="color: rgb(68, 68, 68);">为隐蔽工程中的安全性加分</strong></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><span style="color: rgb(68, 68, 68);">贝壳精工在辅材选择上更是慎之又慎，为确保装修品质，贝壳精工甄选全球大牌辅材，只为家的基石更牢固，更安全。贝壳精工为业主打造从设计、施工以及验收的全面优质服务，同时，也更加着重强调隐蔽工程，通过VR全面记录水电隐蔽工程，实现全方位透明验收，为业主打造安心体验。</span></p><p class="ql-align-justify"><br></p><p class="ql-align-center"><img style="max-width:100%;height:auto" src="http://articlevie001.oss-cn-beijing.aliyuncs.com/1594803662614.png"></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><span style="color: rgb(68, 68, 68);">在隐蔽工程中的电气连接辅材选择上，贝壳精工选择安全性能高的德国万可电线连接器产品，为接线提供标准化工艺以及安全的接线保障。</span></p><p class="ql-align-justify"><br></p><p class="ql-align-center"><img style="max-width:100%;height:auto" src="http://articlevie001.oss-cn-beijing.aliyuncs.com/1594802825364.png"></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><span style="color: rgb(68, 68, 68);">对比下方使用德国万可电线连接器接线与传统黑胶布接线，大家是不是觉得无论从安全性还是颜值方面，德国万可电线连接器都更胜一筹。为此，贝壳精工在其隐蔽工程可视化的项目中，选择德国万可电线连接器产品，接线整齐，告别凌乱，让安全看得见。</span></p><p class="ql-align-justify"><br></p><p class="ql-align-center"><img style="max-width:100%;height:auto" src="http://articlevie001.oss-cn-beijing.aliyuncs.com/1594802842646.jpg"></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><strong class="ql-size-large" style="color: rgb(68, 68, 68);">安全</strong></p><p class="ql-align-justify"><strong class="ql-size-large" style="color: rgb(68, 68, 68);">是所有幸福的起点</strong></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><span style="color: rgb(68, 68, 68);">德国万可电线连接器选材优质，具有耐高温、抗腐蚀、防漏电等优势，从而有效杜绝电气安全隐患，助力贝壳精工提升装修品质，同时，也为每个家庭的安全保驾护航。</span></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><img style="max-width:100%;height:auto" src="http://articlevie001.oss-cn-beijing.aliyuncs.com/1594802861989.png"></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><strong style="color: rgb(68, 68, 68);">无松脱风险：</strong></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><span style="color: rgb(68, 68, 68);">连接器所采用的笼式弹簧连接技术可实现电线间的气密性电气连接，此外，弹簧所产生的夹持力可根据电线横截面积的大小自动调节，从而确保电线连接没有松脱的风险。</span></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><strong style="color: rgb(68, 68, 68);">选材优质，耐腐蚀性强：</strong></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><span style="color: rgb(68, 68, 68);">德国万可电线连接器选用的优质弹簧夹持材料，抗腐蚀、耐老化且阻燃性能优异，耐高温性强，在其六十多年的应用中，没有发生一例腐蚀现象。</span></p><p class="ql-align-justify"><br></p><video class="ql-video" controls="controls" style="width: 100%;" type="video/mp4" src="https://fluploadvideo.oss-cn-beijing.aliyuncs.com/studio_course/20200715164953.mp4"></video><p class="ql-align-justify"><br></p><p class="ql-align-justify"><span style="color: rgb(68, 68, 68);">本试验模拟家庭用电过程中电流过载的极限试验，德国万可电线连接器电流过载的阻燃表现。经过5分钟130A电流过载通电后，接点仍完好无损，电线连接依然牢固，夹持质量仍然符合规范要求。通过试验，德国万可电线连接器的安全性和可靠性一览无遗。</span></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><strong style="color: rgb(68, 68, 68);">导流条无断裂风险：</strong></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><span style="color: rgb(68, 68, 68);">在导体材料的使用中，德国万可所用的导流条是由电解铜作为标准原料的，具有良好的导电性和良好的化学稳定性，而没有受压断裂的危险。</span></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><strong class="ql-size-large" style="color: rgb(68, 68, 68);">操作简便</strong></p><p class="ql-align-justify"><strong class="ql-size-large" style="color: rgb(68, 68, 68);">实现标准化接线工艺</strong></p><p class="ql-align-justify"><br></p><p class="ql-align-justify"><span style="color: rgb(68, 68, 68);">德国万可221系列电线连接器凭借着独特的笼式弹簧连接技术，连接快速、简单、无需接线工具，打开操作杆，插入电线，闭合操作杆接线完成，无需接线工具，方便快捷，助力大幅提升电气安装效率。</span></p><p class="ql-align-justify"><br></p><video class="ql-video" controls="controls" style="width: 100%;" type="video/mp4" src="https://fluploadvideo.oss-cn-beijing.aliyuncs.com/studio_course/20200715164848.mp4"></video><p class="ql-align-justify"><br></p><p class="ql-align-justify"><span style="color: rgb(68, 68, 68);"现如今，业主对于装修的品质要求不断提升，越来越多的关注到每个细节，为此，贝壳精工凭借其开放数据资源和技术能力，打造透明化装修，德国万可电线连接器凭借其靓丽的颜值以及安全性能助其提升装修品质。</span'
          nowshowcontent: res.data.data.safetyContent.replace(/\\/g, '').replace(/\<img/gi, '<img style="max-width:100%;height:auto"').replace( /^["|'](.*)["|']$/g, "$1")

        })
        if(vm.data.nowshowcontent.match('<video')){
                  var sssindex = vm.data.nowshowcontent.match('<video').index;
        var eeeindex = vm.data.nowshowcontent.match('</video>').index;
        var vide = vm.data.nowshowcontent.slice(sssindex,eeeindex)
        var srcstart = vide.match('src=').index;
        var srcend = vide.match('.mp4">').index;
        vm.setData({
          videourl:vide.slice(srcstart+5,srcend)+'.mp4'
        })
        }


      }
    });






  },
    // 修改积分
    changeJifen(){
      var that = this
      var time = new Date().getTime()
      wx.request({
        url: getApp().globalData.baseUrl + '/wago/jifen/changeJifen',
        data: {
          userid:getApp().globalData.openid,
          changejifen:that.data.integralRule.changejifen,
          changename:that.data.integralRule.name,
          changetime:time
        },
        method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        // header: {}, // 设置请求的 header
        success: function(res){
          // success
          // console.log('修改积分返回的数据',res)
          // if(res.data.flag){
          //   wx.showToast({
          //     title: '已为您添加积分',
          //     icon:'none'
          //   })
          // }
        },
        fail: function() {
          // fail
        },
        complete: function() {
          // complete
        }
      })
    },

  //分享
  onShareAppMessage: function (e) {
    var vm = this;
    var id = e.target.dataset.articleid;
    var img = e.target.dataset.img;
    var title = e.target.dataset.title;
    var nowtypeid = this.data.nowtypeid
    var icontent = e.target.dataset.icontent;
    var userid = getApp().globalData.openid;
    console.log('我分享了')
    wx.request({
      url: getApp().globalData.baseUrl + '/wago/jifen/findJifenControl',
      data: {
        id:'8'
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function(res){
        // success
        console.log('查询积分规则',res)
        if(res.data.flag){
          vm.setData({
            integralRule:res.data.data
          })
          vm.changeJifen()
        }
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
    
    return {
      
      title: title, //自定义转发标题
      path: "/pages/newInfo3/newInfo3?id="+id+'&userid='+userid ,
      imageUrl: img, //分享图片 宽高比 5:4
      success:function(){
        
      }
    };



    
    

  }


})


